<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" >
<head>


	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>首页</title>
	<link rel="stylesheet" href="../static/css/main.css" type="text/css" />
	<!-- 导入首页轮播图css和js脚本 -->
	<link type="text/css" href="../static/css/autoplay.css" rel="stylesheet" />
	<script type="text/javascript" src="../static/js/autoplay.js"></script>
	<meta charset="UTF-8">
	<title>书城首页</title>
	<link type="text/css" rel="stylesheet" th:href="@{../static/css/style.css}" >
	<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
	<script>

		$(function () {
			$(".delete_Cart_book").click(function () {

				let name = $(this).attr("book_name");
				let username = $(".um_span").text();
				$.ajax(
						{
							url: "orders/deleteCartBook",
							type: "delete",
							data:{
								"name":name,
								"username":username
							},
							success:function (data) {
								location.href="cart?username="+username;
							}
						}
				)
				return false;
			})

		})


	</script>
</head>


<body class="main">

<div id="divhead">
	<table cellspacing="0" class="headtable">
		<tr>
			<td>
				<a href="#">
					<img src="../static/images/logo.png" width="200" height="60" border="0" />
				</a>
			</td>


			<td style="text-align:right">
				<th:block th:if="${session.user!=null}">
					<img src="../static/images/cart.gif" width="26" height="23" style="margin-bottom:-4px" />&nbsp;
					<a th:href="'/book/cart?username='+${session.user.username}" >购物车</a>
				</th:block>
				| <a href="#">帮助中心</a>
				| <a href="#">我的帐户</a>

				<th:block th:if="${session.user==null}">
					|<a th:href="@{/book/login}">登录</a>
					|<a th:href="@{/book/register}">注册</a>
				</th:block>
				<th:block th:if="${session.user!=null}">
					<span>欢迎<span class="um_span" th:text="${session.user.username}"></span>光临书城</span>
					|<a th:href="@{/order}">我的订单</a>
					|<a th:href="@{/loginClose}">注销</a>&nbsp;&nbsp;
				</th:block>
			</td>





		</tr>
	</table>
</div>

<div id="divmenu">
	<a href="index?category=文学">文学</a>
	<a href="index?category=生活">生活</a>
	<a href="index?category=计算机">计算机</a>
	<a href="index?category=外语">外语</a>
	<a href="index?category=经管">经管</a>
	<a href="index?category=励志">励志</a>
	<a href="index?category=社科">社科</a>
	<a href="index?category=学术">学术</a>
	<a href="index?category=少儿">少儿</a>
	<a href="index?category=艺术">艺术</a>
	<a href="index?category=原版">原版</a>
	<a href="index?category=科技">科技</a>
	<a href="index?category=考试">考试</a>
	<a href="index?category=生活百科">生活百科</a>
	<a href="index?category=" style="color:#FFFF00">全部商品目录</a>
</div>


<div id="divsearch">
	<form action="#" id="searchform">
		<table width="100%" border="0" cellspacing="0">
			<tr>
				<td style="text-align:right; padding-right:220px">
					Search
					<input type="text" name="textfield" class="inputtable" id="textfield" value="请输入书名"
						   onmouseover="this.focus();"
						   onclick="my_click(this, 'textfield');"
						   onBlur="my_blur(this, 'textfield');"/>
					<a href="#">
						<img src="../static/images/serchbutton.gif" border="0" style="margin-bottom:-4px" onclick="search()"/>
					</a>
				</td>
			</tr>
		</table>
	</form>
</div>

	<div th:if="${cart}!=null" id="main">

		<table>
			<tr>
				<td>商品名称</td>
				<td>数量</td>
				<td>单价</td>
				<td>金额</td>
				<td>图片</td>
				<td>操作</td>
			</tr>
			<tr th:each="cart:${cart}">
				<td th:text="${cart.name}">时间简史</td>
				<td th:text="${cart.count}">2</td>
				<td th:text="${cart.price}">30.00</td>
				<td th:text="${cart.count}*${cart.price}">60.00</td>
				<td>
					<img class="book_cart_img" alt="" th:src="${cart.imgurl}" />
				</td>
				<td><a href="#" class="delete_Cart_book" th:book_name="${cart.name}">删除</a></td>
			</tr>
		</table>

		<div class="cart_info">
			<span class="cart_span">购物车中共有<span class="b_count" th:text="${toTalPriceAndTotalCount.totalCount==null?0:toTalPriceAndTotalCount.totalCount}"></span>件商品</span>
			<span class="cart_span">总金额<span class="b_price" th:text="${toTalPriceAndTotalCount.totalPrice==null?0:toTalPriceAndTotalCount.totalPrice}">90.00</span>元</span>
			<span class="cart_span"><a th:href="'/book/clearout?username='+${session.user.username}" class="clearCart">清空购物车</a></span>
			<script>
				$(".clearCart").click(function () {

					let b = confirm("确认清空购物车吗？");
					return b;
				})
			</script>
			<span class="cart_span">
				<a th:href="'/book/checkout?username='+${session.user.username}" style="color:red;" >去结账</a>
			</span>
		</div>

	</div>

<div id="divfoot">
	<table width="100%" border="0" cellspacing="0" >
		<tr>
			<td rowspan="2" style="width:10%">
				<img src="../static/images/logo.png" width="195" height="50"
					 style="margin-left:175px" />
			</td>
			<td style="padding-top:5px; padding-left:50px">
				<a href="#">
					<font color="#747556"><b>CONTACT US</b></font>
				</a>
			</td>
		</tr>
		<tr>
			<td style="padding-left:50px">
				<font color="#CCCCCC">
					<b>COPYRIGHT 2015 &copy; BookStore All Rights RESERVED.</b>
				</font>
			</td>
		</tr>
	</table>
</div>

</body>
</html>
